package com.shwread.android.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

import com.shwread.android.qysw10000243.R;

import org.geometerplus.android.util.QyreaderPerferencesUtil;

import logic.constants.Const;


public class LocationFailDialog
        extends
        Dialog
{
	protected TextView tvText;
	protected TextView tvOk;
	protected View     vDivider;
	protected View     vCancel;
	private CheckBox   vCheckBox;
	protected TextView vTitle;
	private Activity   activity;
	
	public LocationFailDialog(Context context) {
		super(context, R.style.common_dialog);
		activity = (Activity) context;
		
		setCanceledOnTouchOutside(true);
		
		findViews();
		setListeners();
		((Button) vCancel).setText("取消");
	}
	
	private void findViews() {
		View view = LayoutInflater.from(activity).inflate(R.layout.location_fail_dialog, null);
		
		tvText = (TextView) view.findViewById(R.id.common_dialog_text);
		tvOk = (TextView) view.findViewById(R.id.common_dialog_ok);
		vDivider = view.findViewById(R.id.common_dialog_divider);
		vCancel = view.findViewById(R.id.common_dialog_cancel);
		vTitle = (TextView) view.findViewById(R.id.common_dialog_title);
		vCheckBox = (CheckBox) view.findViewById(R.id.common_dialog_checkbox);
		setContentView(view);
	}
	
	private void setListeners() {
		ClickListener l = new ClickListener();
		
		tvOk.setOnClickListener(l);
		vCancel.setOnClickListener(l);
		vCheckBox.setOnClickListener(l);
	}
	
	private class ClickListener
	        implements
	        View.OnClickListener
	{
		
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
				case R.id.common_dialog_ok:
					QyreaderPerferencesUtil.getInstance(activity, Const.phone_number).setIsShowLocationFailDialog(false);
					dismiss();
					startWirelessSettingsActivity(activity);
					break;
				case R.id.common_dialog_cancel:
					dismiss();
					break;
			}
		}
		
	}
	
	public static void startWirelessSettingsActivity(Activity context) {
		try
		{
			Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
			intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
			context.startActivity(intent);
		}
		catch (ActivityNotFoundException e)
		{
			
		}
	}
}
